home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / Log Library 1.01 / LogLib ƒ / Readme < prev   
Encoding:
Text File  |  1994-01-15  |  3.2 KB  |  99 lines  |  [TEXT/KAHL]

  1.  
  2.     LogLib 1.0
  3.     
  4.     C routines to simplify the use of program logs.
  5.     
  6.     ©1994 by Dave Nebinger (dnebing@andy.bgsu.edu)
  7.     All Rights Reserved.
  8.         
  9.     Feel free to use this where ever you wish, just drop me some email
  10.     stating what you are doing with it.
  11.  
  12.  
  13.     
  14. ==========
  15. Introduction
  16. ==========
  17.  
  18.     I don't know about the rest of ya, but I know that I for some things a log file comes in really handy.
  19. I mean, for testing background only apps, inits, etc., it is hard to come up with an alternative (besides
  20. dropping into MacsBug ;-) solution that will allow a programmer to see what's going on with the project.
  21.  
  22.     I am currently working on a project that runs in the background and uses mactcp.  That's when I
  23. realized that I could really use a log file to track what was going on with the app.  So I created this one.
  24.  
  25.     It is simply a set of routines to open and write to a log file in the system folder.  Actually, the
  26. routine is set up to store the log in one of two places-the Preferences folder, or a folder of your
  27. desire within the Preferences folder.
  28.  
  29. ==========
  30. Function Description
  31. ==========
  32.  
  33.     The functions are pretty simple, although you are required to include at least the "ansi-small"
  34. library.
  35.     
  36. Boolean InitLog(Str255 fold,short* vref,long* pid,long* fid);
  37.  
  38.     InitLog should be called pretty early (I do it where after initializing the toolbox).  It locates the
  39. Preferences folder in the system folder.  If you also give a name to 'fold', then the function will also
  40. find the directory id for that folder (InitLog will create the folder if it doesn't already exist).
  41.  
  42. short OpenLog(Str255 name,short vref,long did);
  43.  
  44.     OpenLog opens the log file with name 'name' and returns the file reference number.  This is the
  45. number that is used in the rest of the functions.  A -1 is returned if there is an error.
  46.  
  47. Boolean Log(short,const char* fmt,...);
  48. Boolean LogTime(short,const char* fmt,...);
  49.  
  50.     These two functions work like fprintf.  LogTime precedes the string that is going to print with
  51. the current date and time.
  52.  
  53. void CloseLog(short);
  54.  
  55.     This function closes the log file.
  56.  
  57. ==========
  58. Usage
  59. ==========
  60.  
  61.     The following is a very simple program which demonstrates how to use the log routines for two
  62. different log files.
  63.     
  64. void main(){
  65.     short vref; /* vol ref num */
  66.     long pdir,fdir; /* preferences folder id, and my folder id */
  67.     short fref1,fref2; /* file reference number */
  68.     
  69.     InitMacintosh(); /* init the mac toolbox */
  70.     if (InitLog("\pTest Log ƒ",&vref,&pdir,&fdir)){ /* then we are set to continue... */
  71.         
  72.         fref1=OpenLog("\pLog File #1",vref,pdir); /* open a log file in the prefs folder */
  73.         fref2=OpenLog("\pLog File #2",vref,fdir); /* open a log file in our created folder */
  74.         
  75.         if ((fref1!=-1)&&(fref2!=-1)){ /* then we can start logging */
  76.         
  77.             LogTime(fref1,"Demo Log Program Open. %c",kNewLine); /* \n is not good for some editors... */
  78.             Log(fref1,"Welcome. %c%c",kNewLine,kNewLine);
  79.             
  80.             LogTime(fref2,"Shutting down now... %c",kNewLine);
  81.             
  82.             CloseLog(fref1);
  83.             CloseLog(fref2);
  84.         }
  85.     }
  86. }
  87.  
  88.  
  89. ==========
  90. Finalè
  91. ==========
  92.  
  93.     Last but not least is the stuff the lawyers just love: use this at your own risk, I am not responsible,
  94.     no warrantee is implied, etc.  However, I am more than happy to discuss any problems that you might
  95.     have with this source.
  96.     
  97.     
  98.     
  99.